package com.situ.firmadmin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.situ.firmadmin.mapper.AuthMapper;
import com.situ.firmadmin.pojo.Auth;
import com.situ.firmadmin.pojo.query.AuthQuery;
import com.situ.firmadmin.pojo.vo.AuthRoleVO;
import com.situ.firmadmin.service.IAuthService;
import com.situ.firmadmin.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthServiceImpl implements IAuthService {
    @Autowired
    private AuthMapper authMapper;

    @Override
    public List<Auth> selectByRole(Integer role) {
        return authMapper.selectByRole(role);
    }

    @Override
    public PageResult selectByPage(AuthQuery authQuery) {
        PageHelper.startPage(authQuery.getPage(), authQuery.getLimit());
        List<AuthRoleVO> list=authMapper.selectByPage(authQuery);
        PageInfo<AuthRoleVO> pageInfo=new PageInfo<>(list);
        int total=(int)pageInfo.getTotal();
        return new PageResult(0,"",total,list);
    }

    @Override
    public void insert(Auth auth) {
        authMapper.insert(auth);
    }

    @Override
    public Auth selectById(Integer id) {
        return authMapper.selectById(id);
    }

    @Override
    public void update(Auth auth) {
        authMapper.update(auth);
    }

    @Override
    public void deleteById(Integer id) {
        authMapper.deleteById(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        authMapper.deleteAll(ids);
    }
    
    @Override
    public void updateStatus(Auth auth) {
        authMapper.updateStatus(auth);
    }
    
    @Override
    public List<Auth> selectByRole2(Integer role) {
        List<Auth> parentList=authMapper.selectParent(role);
        System.out.println(parentList);
        for(Auth auth:parentList){
            auth.setChildrenAuth(authMapper.selectByRole2(role,auth.getId()));
        }
        return parentList;
    }
    
    @Override
    public List<Auth> selectAllParent() {
        return authMapper.selectAllParent();
    }
}
